var { refreshWinState } = require('./backApi');

const {app, ipcMain, BrowserWindow} = require('electron');



ipcMain.on('ui-event', (e, data) => {
  manageUIEvent(data);
})

const EVENT_LIST = [
  {type: 'minimize', invoke: () => BrowserWindow.getFocusedWindow()?.minimize()},
  {type: 'maximize', invoke: () => BrowserWindow.getFocusedWindow()?.maximize()},
  {type: 'restoremize', invoke: () => BrowserWindow.getFocusedWindow()?.restore()},
  {type: 'close', invoke: () => app?.exit()},
  {type: 'refresh-win-state', invoke: refreshWinState}
]


// 处理前端传递过来的事件
function manageUIEvent (e) {
  console.log('evt: ', e.type);
  let evtHandler = EVENT_LIST.find(item => item.type === e?.type);
  if (evtHandler) {
    return evtHandler.invoke(e.data)
  }
  switch(e?.type) {
    default: {
      break;
    }
  }
}
